package algotithm.leetcode.dp.test718;

/**
 * @author 25068
 * @Date 2021/4/28 22:34
 * @Title c
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] A = {1,2,3,2,1};
        int[] B = {3,2,1,4,7};
        int length = solution.findLength(A, B);
        System.out.println(length);
    }

    public int findLength(int[] A, int[] B) {
        int n = A.length;
        int m = B.length;
        int[][] dp = new int[n + 1][m + 1];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dp[i + 1][j + 1] = A[i] == B[j] ? dp[i][j] + 1 : 0;
                ans = Math.max(ans,dp[i + 1][j + 1]);
            }
        }
        return ans;
    }
}

